package view.component.menu
{
import core.Language;

import framework.core.ComponentBuilder;
import framework.view.components.button.ButtonProxy;

import mapengine.interfaces.IFactoryBuilding;

import view.component.window.FactoryProductUI;
import view.component.window.UpgradeFactoryBuildingUI;

/**
 * FactoryBuildingMenu
 * @author jliang
 *
 */
public class FactoryBuildingMenu extends MapBuildingMenu
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function FactoryBuildingMenu()
	{
		super();
	}
	//==========================================================================
	//  Protected methods
	//==========================================================================
	protected function get produceBtn():ButtonProxy
	{
		return proxys["produceBtn"];
	}
	//==========================================================================
	//  Overridden methods: MapBuildingMenu
	//==========================================================================
	override protected function get skinReference():String
	{
		return "swf.ui.FactoryBuildingMenuSkin";
	}
	
	override protected function get proxyMapping():Array
	{
		return [ 
			{ skin:"produceBtn", classRef: ButtonProxy, id:"produceBtn", text:Language.getText("@building_menu_produce_button_label"), onClick:clickToProduceHandler }
		].concat(super.proxyMapping);
	}
	
	override protected function init():void
	{
		super.init();
		
		if (IFactoryBuilding(data).isProducing)
		{
			produceBtn.enabled = false;
			upgradeBtn.enabled = false;
		}
	}
	//==========================================================================
	//  Event handlers
	//==========================================================================
	protected function clickToProduceHandler():void
	{
		if (IFactoryBuilding(data).isProducing) return;
		
		var window:FactoryProductUI = ComponentBuilder.create(FactoryProductUI);
		window.data = IFactoryBuilding(data);
		window.show();
	}
	
	override protected function clickToUpgradeHandler():void
	{
		if (!data.canUpgrade) return;
		
		var window:UpgradeFactoryBuildingUI = ComponentBuilder.create(UpgradeFactoryBuildingUI);
		window.data = data;
		window.show();
	}
}
}



